Make the parser tuple exported#5
Open
singularperturbation wants to merge 2 commits intoPMunch:masterfrom
Open
Conversation
added 2 commits
February 5, 2020 02:38
Thought about adding a do_export flag in createParser, but that made things awkward. Had to specify `do_export=true` or `do_export=false` even when I had a default in the createParser macro.
Add the tuple return type to the generated code and export it:
```
type
Header* = tuple[payload_length: uint32, frame_type: int8, flags: int8, R: int8,
stream_identifier: uint32]
```
Author
|
I also made the return type parsed and generated as a tuple so that the type can be used outside of the module: createParser(frame_header, Header):
u24: payload_length
8: frame_type
8: flags
1: R = 0
u31: stream_identifier
## Generates from -d:binaryparseEcho
type
Header* = tuple[payload_length: uint32, frame_type: int8, flags: int8, R: int8,
stream_identifier: uint32]
proc `:tmp`_258099(stream: Stream): Header =
stream.readDataBE(result[0].addr, 3)
result[0] = (result[0] shr 0) and 16777215
stream.readDataBE(result[1].addr, 1)
stream.readDataBE(result[2].addr, 1)
stream.peekDataBE(result[3].addr, 1)
result[3] = (result[3] shr 7) and 1
if result[3] != 0:
raise newException(MagicError, "Magic with size " &
$1 & " didn\'t match value " &
$0 & ", read: " &
$result[3])
stream.readDataBE(result[4].addr, 4)
result[4] = (result[4] shr 0) and 2147483647
proc `:tmp`_258100(stream: Stream; input: var Header) =
var :tmp_258066: int64 = 0
stream.writeDataBE(input[0].addr, 3)
stream.writeDataBE(input[1].addr, 1)
stream.writeDataBE(input[2].addr, 1)
:tmp_258066 = :tmp_258066 shl 24
:tmp_258066 = :tmp_258066 or
(input[4] and 2147483647).int64 shl 0
stream.writeDataBE(:tmp_258066.addr, 4)
:tmp_258066 = 0
let frame_header* = (get: :tmp_258099, put: :tmp_258100) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Very minor change - I wanted to make sure that the (get, put) tuple was exported. I think I want to make the tuple type exportable as well. That way, it's easier to use this in a package.
Thought about adding a do_export flag in createParser, but that made things awkward.
Had to specify
do_export=trueordo_export=falseeven when I had a default in thecreateParser macro.